package com.kfh.ybracelet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kfh.ybracelet.R;
import com.kfh.ybracelet.bean.SafeAreaResult;
import com.kfh.ybracelet.utils.CommonUtils;

import java.util.List;

/**
 * 安全区域
 * Created by Aaron on 15/8/4.
 */
public class SafeAreaAdapter extends BaseAdapter {
    private List<SafeAreaResult.AreaList> temlist;
    private Context context;
//    private boolean isDelete;
//
//    public void setIsDelete(boolean isDelete) {
//        this.isDelete = isDelete;
//    }

    //0是刚进来的模式  1 是删除模式  2 是正常模式(非删除模式)
//    private int style = 0;

//    private ObjectAnimator animator;

    public SafeAreaAdapter(Context context, List<SafeAreaResult.AreaList> temlist) {
        this.context = context;
        this.temlist = temlist;
    }

    public void setData(List<SafeAreaResult.AreaList> temlist) {
        this.temlist = temlist;
    }
//    public void setStyle(int style) {
//        this.style = style;
//    }

    @Override
    public int getCount() {
        return temlist.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_safe_area, null);
            viewHolder = new ViewHolder();

            viewHolder.tv_left_item = (TextView) convertView.findViewById(R.id.tv_left_item);
            viewHolder.tv_right_item = (TextView) convertView.findViewById(R.id.tv_right_item);

//            viewHolder.ll_left = (LinearLayout) convertView.findViewById(R.id.ll_left);
//            viewHolder.iv_delete = (ImageView) convertView.findViewById(R.id.iv_delete);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

//        if (isDelete) {
//            float x = viewHolder.rl_left.getTranslationX();
//            ObjectAnimator animator = ObjectAnimator.ofFloat(viewHolder.ll_left, "translationX", 0, DensityUtil.dip2px(context,50));
//            animator.setDuration(500);
//            animator.start();
//
//        }

//        switch (style) {
//
//            case 0:
//
//                animator = ObjectAnimator.ofFloat(viewHolder.ll_left, "translationX", 0, -DensityUtil.dip2px(context, 50));
//                animator.setDuration(0);
//
//                break;
//
//            case 1:
//
//                animator = ObjectAnimator.ofFloat(viewHolder.ll_left, "translationX", -DensityUtil.dip2px(context, 50), 0);
//                animator.setDuration(500);
//
//                break;
//
//            case 2:
//                animator = ObjectAnimator.ofFloat(viewHolder.ll_left, "translationX", 0, -DensityUtil.dip2px(context, 50));
//                animator.setDuration(500);
//
//                break;
//
//        }

//        animator.start();

        viewHolder.tv_left_item.setText(CommonUtils.isNull(temlist.get(position).areaName) ? "" : temlist.get(position).areaName);
        viewHolder.tv_right_item.setText(CommonUtils.isNull(temlist.get(position).radius + "") ? "" : "方圆" + temlist.get(position).radius + "m");

//        viewHolder.iv_delete.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                LogUtil.e("TAG", "删除点击事件==>" + position);
//            }
//        });

        return convertView;
    }

    private class ViewHolder {
        TextView tv_left_item;
        TextView tv_right_item;
//        LinearLayout ll_left;
//        ImageView iv_delete;
    }

}
